package com.tech.tool.handle;

import com.tech.tool.config.ProjectUrlConfig;
import com.tech.tool.exception.ToolException;
import com.tech.tool.exception.ToolerAuthorizeException;
import com.tech.tool.utils.ResultVOUtil;
import com.tech.tool.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

@ControllerAdvice
public class ToolExceptionHandler {

    @Autowired
    ProjectUrlConfig projectUrlConfig;

    @ExceptionHandler(value = ToolException.class)
    @ResponseBody
    public ResultVO handlerToolException(ToolException e) {
        return ResultVOUtil.error(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(value = ToolerAuthorizeException.class)
    @ResponseBody
    @ResponseStatus(HttpStatus.FORBIDDEN)
    public ResultVO handlerAuthException(ToolerAuthorizeException e) {
        return ResultVOUtil.error(e.getCode(), e.getMessage());
    }

}
